//获取cookie数据
function getCookie(cookieName) {
  const strCookie = document.cookie
  const cookieList = strCookie.split(';')
  for (let i = 0; i < cookieList.length; i++) {
    const arr = cookieList[i].split('=')
    if (cookieName === arr[0].trim()) {
      return arr[1]
    }
  }
  return ''
}
// 添加cookie
/**
 * @param {*} cname key
 * @param {*} cvalue value
 * @param {*} exmin 单位：半小时
 */
function setCookie(cname,cvalue,exmin) {
  var d = new Date();
  // 半小时
  d.setTime(d.getTime()+(exmin*30*60*1000));
  var expires = "expires="+d.toGMTString();
  document.cookie = cname + "=" + cvalue + "; " + expires + ";path=/";
}
//删除cookie数据
function deleteCookie(name) {
  setCookie(name, "", { expireDays: -1 }); //将过期时间设置为过去来删除一个cookie
}

export default {getCookie, deleteCookie, setCookie};